home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / PowerPlant / Multi-Panel Dialogs 1.1 / MPD Sources / CMPDIncludeView.cp < prev    next >
Encoding:
Text File  |  1996-11-13  |  7.1 KB  |  194 lines  |  [TEXT/R*ch]

  1. // ===========================================================================
  2. //    File:                        CMPDIncludeView.cp
  3. // Version:                    1.0 - Feb 1, 1996
  4. //    Author:                    Mike Shields (mshields@inconnect.com)
  5. //                            
  6. //    Copyright ©1996 Mike Shields. All rights reserved.
  7. //    I hereby grant users of CMPDIncludeView permission to use it (or any modified 
  8. //    version of it) in applications (or any other type of Macintosh software 
  9. //    like extensions -- freeware, shareware, commercial, or other) for free, 
  10. //    subject to the terms that:
  11. //
  12. //        (1)  This agreement is non-exclusive.
  13. //
  14. //        (2)  I, Mike Shields, retain the copyright to the original source code.
  15. //
  16. //    These two items are the only required conditions for use. However, I do have 
  17. //    an additional request. Note, however, that this is only a request, and 
  18. //    that it is not a required condition for use of this code.
  19. //
  20. //        (1) That I be given credit for CMPDIncludeView code in the copyrights or 
  21. //            acknowledgements section of your manual or other appropriate documentation.
  22. //
  23. //
  24. //    I would like to repeat that this last item is only a request. You are prefectly 
  25. //    free to choose not to do any or all of them.
  26. //    
  27. //        This source code is distributed in the hope that it will be useful,
  28. //        but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. //        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  30. // ===========================================================================
  31. //    CMPDIncludeView.h        <- double-click + Command-D to see class declaration
  32. //
  33. // Class which controls the loading and disposing of a panel subpane in a
  34. // multi-pane dialog.
  35. // Also handles the relationship of getting and setting the data represented by 
  36. // that particular panel
  37.  
  38. #include "CMPDIncludeView.h"
  39. #include "CMPDPanel.h"
  40.  
  41. #include <PP_Constants.h>
  42.  
  43. #pragma mark === Construction & Destruction ===
  44.  
  45. //----------------------------------------------------------------------------------------
  46. // CMPDIncludeView::CreateFromStream 
  47. //----------------------------------------------------------------------------------------
  48. // Static function registered with URegistrar to create a MPDIncludeView from the data 
  49. // in a stream
  50. CMPDIncludeView* CMPDIncludeView::CreateFromStream(LStream *inStream)
  51. {
  52.     return (new CMPDIncludeView(inStream));
  53. }
  54.  
  55. //----------------------------------------------------------------------------------------
  56. // CMPDIncludeView::CMPDIncludeView 
  57. //----------------------------------------------------------------------------------------
  58. // Default constructor
  59. CMPDIncludeView::CMPDIncludeView()
  60. {
  61. }
  62.  
  63. //----------------------------------------------------------------------------------------
  64. // CMPDIncludeView::CMPDIncludeView 
  65. //----------------------------------------------------------------------------------------
  66. // Create form th data in the stream
  67. CMPDIncludeView::CMPDIncludeView(LStream *inStream)
  68.     : CIncludeView(inStream)
  69. {
  70. }
  71.  
  72. //----------------------------------------------------------------------------------------
  73. // CMPDIncludeView::~CMPDIncludeView 
  74. //----------------------------------------------------------------------------------------
  75. // Destructor
  76. CMPDIncludeView::~CMPDIncludeView()
  77. {
  78. }
  79.  
  80. #pragma mark === Panel Management ===
  81. //----------------------------------------------------------------------------------------
  82. // CMPDIncludeView::LoadNewMPDPanel
  83. //----------------------------------------------------------------------------------------
  84. // Load in a new MPD panel and set the data for it. As we do this we'll get the 
  85. // data from the last panel included in this view and return that data.
  86. void CMPDIncludeView::LoadNewMPDPanel(ResIDT inPanelID, Handle inNewPanelData, 
  87.                                                     Handle inOldPanelData, Boolean inRefresh)
  88. {
  89.     if ( mPaneID != PaneIDT_Undefined )
  90.     {
  91.         // get the data from the current MPD panel
  92.         GetPanelData(inOldPanelData);
  93.     }
  94.     
  95.     // install the new view.
  96.     IncludeView(inPanelID, false);
  97.     
  98.     if ( mPaneID != PaneIDT_Undefined )
  99.     {        
  100.         // and set the MPD data into the new panel
  101.         UseNewPanelData(inNewPanelData, false);
  102.  
  103.         // force the included pane to be redrawn. This works better than just refreshing the pane.
  104.         if ( inRefresh )
  105.         {
  106.              Refresh();
  107.         }
  108.     }
  109. }
  110.  
  111. //----------------------------------------------------------------------------------------
  112. // CMPDIncludeView::UseNewPanelData
  113. //----------------------------------------------------------------------------------------
  114. // Tell the included panel that it needs to display new data.
  115. void CMPDIncludeView::UseNewPanelData(Handle inNewPanelData, Boolean inRefresh)
  116. {
  117.     SignalIf_(inNewPanelData == nil);
  118.     CMPDPanel* aPanel = dynamic_cast<CMPDPanel*>(mCurrentIncludedPane);
  119.     SignalIf_(aPanel == nil );
  120.  
  121.     // Setting the ClipRgn to nil will prevent the LStdControl based controls from drawing
  122.     // as the SetData call updates the state of the controls to reflect the current data.
  123.     StClipRgnState    saveClip(nil);    
  124.     
  125.     if ( aPanel != nil )
  126.     {
  127.         aPanel->SetData(inNewPanelData);
  128.     }
  129.     
  130.     if ( inRefresh )
  131.         Refresh();
  132. }
  133.  
  134. //----------------------------------------------------------------------------------------
  135. // CMPDIncludeView::GetPanelData
  136. //----------------------------------------------------------------------------------------
  137. // ask the included panel for the data it currently contains.
  138. void CMPDIncludeView::GetPanelData(Handle inDataToReplace)
  139. {
  140.     SignalIf_(inDataToReplace == nil);
  141.     CMPDPanel* aPanel = dynamic_cast<CMPDPanel*>(mCurrentIncludedPane);
  142.     SignalIf_(aPanel == nil );
  143.     if ( aPanel != nil )
  144.     {
  145.         // return the data contained in the current panel
  146.         aPanel->GetData(inDataToReplace);
  147.     }
  148. }
  149.  
  150. //----------------------------------------------------------------------------------------
  151. // CMPDIncludeView::ValidatePanel
  152. //----------------------------------------------------------------------------------------
  153. // ask the contained panel to validate its contents. 
  154. //     Return TRUE if data is valid, FALSE if not
  155. Boolean CMPDIncludeView::ValidatePanel(void)
  156. {
  157.     CMPDPanel* aPanel = dynamic_cast<CMPDPanel*>(mCurrentIncludedPane);
  158.     SignalIf_(aPanel == nil );
  159.     if ( aPanel != nil )
  160.         return aPanel->ValidatePanel();
  161.     else
  162.         return true;
  163. }
  164.  
  165. //----------------------------------------------------------------------------------------
  166. // CMPDIncludeView::WantDefaultsButton
  167. //----------------------------------------------------------------------------------------
  168. // ask the contained panel if it needs/wants the Use Defaults Button. 
  169. //     Return TRUE if it does, FALSE if not
  170. Boolean CMPDIncludeView::WantDefaultsButton(void)
  171. {
  172.     CMPDPanel* aPanel = dynamic_cast<CMPDPanel*>(mCurrentIncludedPane);
  173.     SignalIf_(aPanel == nil );
  174.     if ( aPanel != nil )
  175.         return aPanel->WantDefaultsButton();
  176.     else
  177.         return false;
  178. }
  179.  
  180. //----------------------------------------------------------------------------------------
  181. // CMPDIncludeView::WantRevertButton
  182. //----------------------------------------------------------------------------------------
  183. // ask the contained panel if it needs/wants the Revert Button. 
  184. //     Return TRUE if it does, FALSE if not
  185. Boolean CMPDIncludeView::WantRevertButton(void)
  186. {
  187.     CMPDPanel* aPanel = dynamic_cast<CMPDPanel*>(mCurrentIncludedPane);
  188.     SignalIf_(aPanel == nil );
  189.     if ( aPanel != nil )
  190.         return aPanel->WantRevertButton();
  191.     else
  192.         return false;
  193. }
  194.